﻿using HybridLab.Virtual.HyperV.Fakes;
using HybridLab.Virtual.Interfaces;
using HybridLab.Virtual.Interfaces.Fakes;
using Microsoft.TeamFoundation.Build.Client.Fakes;
using Microsoft.TeamFoundation.Lab.Client.Fakes;
using Microsoft.TeamFoundation.Lab.Workflow.Activities.Fakes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HybridLab.Virtual.UnitTests.Utils
{
	internal class TestUtil
	{
		public static StubIBuildDetail GetFakeBuildDetail()
		{
			return new StubIBuildDetail()
			{
			};
		}

		public static Dictionary<string, List<string>> GetFakeSnapshots()
		{
			var snapshots = new Dictionary<string, List<string>>();
			snapshots["TestMachine1"] = new List<string>() { "Clean" };
			snapshots["TestMachine2"] = new List<string>() { "Clean" };
			return snapshots;
		}

		public static IVirtualHost GetFakeHost(Dictionary<string, List<string>> snapshots, Dictionary<string, string> appliedSnapshots)
		{
			var vmList = new List<IVirtualMachine>();
			snapshots.Keys.ToList().ForEach(k => vmList.Add(CreateFakeVM(k, snapshots, appliedSnapshots)));
			return new StubIVirtualHost()
			{
				GetVMs = () => vmList
			};
		}

		private static StubIVirtualMachine CreateFakeVM(string name, Dictionary<string, List<string>> snapshots, Dictionary<string, string> appliedSnapshots)
		{
			return new StubIVirtualMachine()
			{
				NameGet = () => name,
				SnapshotsGet = () => snapshots[name],
				ApplySnapshotString = (s) =>
				{
					// this will throw if the snapshot does not exist
					var snap = snapshots[name].Single(ss => ss == s);
					appliedSnapshots[name] = s;
				},
				CreateSnapshotString = (s) => snapshots[name].Add(s),
			};
		}

		public static ShimDeploymentDetails GetFakeDeploymentDetails()
		{
			return new ShimDeploymentDetails()
			{
				PostDeploymentSnapshotNameGet = () => "Test",
			};
		}
	}
}
